package cn.kgc.test.util;

import cn.kgc.test.annotation.Bean;

import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;

/**
 * @Author: 课工场
 * @Version: v1.0  2023/2/26
 * @Description:
 */
public class BeanUtils {


    public static Object createByBeanAnnotation(Class clazz){

        Annotation annotation = clazz.getAnnotation(Bean.class);
        if(annotation==null){
            throw new RuntimeException("当前类对象没有bean注解，无法创建对象");
        }else {
            try {
                Constructor declaredConstructor = clazz.getDeclaredConstructor();
                declaredConstructor.setAccessible(true);
                Object o = declaredConstructor.newInstance();
                return  o ;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }

}
